package com.ad.pet.app.main.desniger;

import android.app.Activity;

import com.ad.pet.api.ApiService;
import com.ad.pet.app.RxDisposable;
import com.ad.pet.common.data.http.AppSubscriber;
import com.ad.pet.common.structure.mvp.AbsBasePresenter;
import com.ad.pet.models.remote.main.DesingerMain;
import com.ad.pet.models.remote.main.DesingerType;

import java.util.List;

import javax.inject.Inject;

/**
 * Created by SEELE on 2019/6/26.
 */
public class DesnigerPresenter extends AbsBasePresenter implements DesnigerContract.Presenter {
    private ApiService mApiService;
    private DesnigerContract.View mView;

    private Activity mActivity;

    private RxDisposable mRxDisposable;

    @Inject
    public DesnigerPresenter(ApiService apiService,
                                Activity activity, RxDisposable rxDisposable) {
        mApiService = apiService;
        mActivity = activity;
        mRxDisposable = rxDisposable;
    }

    @Override
    public void onCreate(DesnigerContract.View view) {
        this.mView = view;
    }


    @Override
    public void onDestroy() {
        if (mRxDisposable != null)
            mRxDisposable.clear();
        if (mActivity != null) mActivity = null;
        mView = null;
    }




    @Override
    public void getDesginerShop(String page, String limit, String longitude, String latitude, String keyword, String province_id, String city_id) {

        mRxDisposable.add(
                mApiService.getDesignerBrandStoreList(page,limit,longitude,latitude,keyword,province_id,city_id).subscribe(new AppSubscriber<List<DesingerMain>>(mView) {
                    @Override
                    public void next(List<DesingerMain> desingerMain) {
                        mView.getDesginerShopSuccess(desingerMain);
                    }
                })
        );
    }

    @Override
    public void getShopService(String shop_id) {
        mRxDisposable.add(
                mApiService.getShopService(shop_id).subscribe(new AppSubscriber<List<DesingerType>>(mView) {
                    @Override
                    public void next(List<DesingerType> desingerMain) {
                        mView.getShopServiceSuccess(desingerMain);
                    }
                })
        );
    }

    @Override
    public void getStoreDetail(String shop_id) {
        mRxDisposable.add(
                mApiService.getStoreDetail(shop_id).subscribe(new AppSubscriber<DesingerMain>(mView) {
                    @Override
                    public void next(DesingerMain desingerMain) {
                        mView.getStoreDetailSuccess(desingerMain);
                    }
                })
        );
    }
}
